package org.ytor.core.sqlflow.plugin;

import org.ytor.core.sqlflow.builder.support.WhereBuilder;
import org.ytor.core.sqlflow.executor.DMLResult;
import org.ytor.core.sqlflow.executor.DQLResult;

import java.util.List;

/**
 * created by yangtong on 2025/8/9 20:54:10
 * <br/>
 * 拦截器，SQL 操作执行前后进行回调
 */
public interface Interceptor {

    /**
     * SELECT SQL构建之前回调，此时可以对最后构建出的 SQL 语句进行修改
     */
    void beforeSelectBuilder(Class<?> table, String tableName, List<String> selectFields, WhereBuilder where);

    /**
     * INSERT SQL构建之前回调，此时可以对最后构建出的 SQL 语句进行修改
     */
    void beforeInsertBuilder(Class<?> table, String tableName);

    /**
     * DELETE SQL构建之前回调，此时可以对最后构建出的 SQL 语句进行修改
     */
    void beforeDeleteBuilder(Class<?> table, String tableName, WhereBuilder where);

    /**
     * UPDATE SQL构建之前回调，此时可以对最后构建出的 SQL 语句进行修改
     */
    void beforeUpdateBuilder(Class<?> table, String tableName, WhereBuilder where);

    /**
     * SELECT 即将执行之前回调
     */
    void beforeSelect(Class<?> tableClass, String tableName, String sql, List<String> selectFields, WhereBuilder where, List<Object> params);

    /**
     * SELECT 执行之后回调
     */
    void afterSelect(Class<?> tableClass, String tableName, String sql, List<String> selectFields, WhereBuilder where, List<Object> params, DQLResult result);

    /**
     * INSERT 即将执行之前回调
     */
    void beforeInsert(Class<?> tableClass, String tableName, String sql, List<Object> params);

    /**
     * INSERT 执行之后回调
     */
    void afterInsert(Class<?> tableClass, String tableName, String sql, List<Object> params, DMLResult result);

    /**
     * DELETE 即将执行之前回调
     */
    void beforeDelete(Class<?> tableClass, String tableName, String sql, WhereBuilder where, List<Object> params);

    /**
     * DELETE 执行之后回调
     */
    void afterDelete(Class<?> tableClass, String tableName, String sql, WhereBuilder where, List<Object> params, DMLResult result);

    /**
     * UPDATE 即将执行之前回调
     */
    void beforeUpdate(Class<?> tableClass, String tableName, String sql, WhereBuilder where, List<Object> params);

    /**
     * UPDATE 执行之后回调
     */
    void afterUpdate(Class<?> tableClass, String tableName, String sql, WhereBuilder where, List<Object> params, DMLResult result);

    /**
     * INSERT 批量执行之前回调
     */
    void beforeInsertBatch(Class<?> tableClass, String tableName, String sql, List<List<Object>> params);

    /**
     * INSERT 批量执行之后回调
     */
    void afterInsertBatch(Class<?> tableClass, String tableName, String sql, List<List<Object>> params, List<DMLResult> results);
}
